import logging
from fastapi import APIRouter, Depends

from app.models.kkgc_model import KkgcModel
from app.services.kkgc_csv_service import kkgc_csv_service
from app.services.kkgc_service import KKGCService, kkgc_service
from app.utils.response_result import resp_500, resp_200

router = APIRouter()
@router.post("/real_time_query", summary="卡扣过车查询接口")
def real_time_query(kkgcModel: KkgcModel, kkgcService: KKGCService = Depends(lambda: kkgc_service)):
    try:
        data = kkgcService.search_kkgc_list(kkgcModel)
        return resp_200(data=data)
    except Exception as e:
        logging.error(f"实时数据查询错误:{str(e)}")
        return resp_500(message=f"卡口过车数据查询错误")

@router.post("/csv_query", summary="卡口过车关联csv查询接口")
def query_csv(kkgcModel: KkgcModel, kkgcService: KKGCService = Depends(lambda: kkgc_service)):
    try:
        data = kkgcService.search_kkgc_csv_list(kkgcModel)
        return resp_200(data=data)
    except Exception as e:
        logging.error(f"实时数据查询错误:{str(e)}")
        return resp_500(message=f"卡口过车数据查询错误")


@router.get("/csv_refresh", summary="卡口过车csv修改后刷新")
def query_csv():
    try:
        data = kkgc_csv_service.refresh_csv()
        return resp_200(data=True, message="刷新成功")
    except Exception as e:
        logging.error(f"刷新失败:{str(e)}")
        return resp_500(message=f"csv刷新失败")

